//
//  ToBeChangeTaskDetailViewController.m
//  MyProject
//
//  Created by Pei on 16/7/18.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "ToBeChangeTaskDetailViewController.h"
#import "WriteToBeChangeTaskViewController.h"
#import "SeePictureViewController.h"
#import "ToBeChangeTaskDetailCell.h"
#import "UserInfo.h"
#import "HTHorizontalSelectionList.h"
#import "RequestPostUploadHelper.h"
#import "JZAlbumViewController.h"

@interface ToBeChangeTaskDetailViewController ()<UITableViewDelegate, UITableViewDataSource, WriteToBeChangeTaskViewControllerDelegate, HTHorizontalSelectionListDelegate, HTHorizontalSelectionListDataSource>
{
    NSDictionary *_currentDic;
    NSString *_currentStr;
    
    UITableView *_myTable;
    
    NSDictionary *_dataDic;
    
    UIView *_footView;
    
    /*
     UIDatePicker *_datePicker;
     UIView *_dateTopView;
     
     NSString *_dateStr;
     */
    
    NSMutableArray *writeArray;
    
    HTHorizontalSelectionList *_segementView;
    NSArray *_titleArray;
    
    UITableView *_secondTable;
    
    NSString *TMP_UPLOAD_IMG_PATH;
    
    //NSDictionary *superDic;
}

@end

@implementation ToBeChangeTaskDetailViewController

- (id)initWithDicFromPush:(NSString*)InspectionIDStr InspectionItemID:(NSString*)InspectionItemIDStr{
    self = [super init];
    if (self) {
        [[YMNetLib getInstance] connectWithAction:Get_ToBeChange_Task_Detail method:@"GET" withContent:[NSString stringWithFormat:@"InspectionID=%d&InspectionItemID=%d",[InspectionIDStr intValue],[InspectionItemIDStr intValue]] withBody:nil withDelegate:self];
        _currentStr = Get_ToBeChange_Task_Detail;
    }
    return self;
}

- (id)initWithDic:(NSDictionary*)dic{
    self = [super init];
    if (self) {
        _currentDic = dic;
        //superDic = dic;
        [self getData];
    }
    return self;
}


- (void)getData
{
    //Get_ToBeSure_Task_Detail
    [[YMNetLib getInstance] connectWithAction:Get_ToBeChange_Task_Detail method:@"GET" withContent:[NSString stringWithFormat:@"InspectionID=%d&InspectionItemID=%d",[[_currentDic valueForKey:@"InspectionID"] intValue],[[_currentDic valueForKey:@"InspectItemID"] intValue]] withBody:nil withDelegate:self];
    _currentStr = Get_ToBeChange_Task_Detail;
}

- (void)NetDoOverSuccess:(NSDictionary*)body
{
    if ([_currentStr isEqualToString:Get_ToBeChange_Task_Detail]) {
        if ([[YMNetDataUtil getSuccessState:body] intValue] == 1)
        {
            _dataDic = body;
            [self initTable];
            [self initFooter];
            
            NSArray *sss = [_dataDic objectForKey:@"InspectTaskList"];
            writeArray = [[NSMutableArray alloc] initWithArray:sss];
            
            NSMutableArray *saveArray = [[NSMutableArray alloc] initWithCapacity:3];
            [saveArray removeAllObjects];
            
            saveArray = [[NSUserDefaults standardUserDefaults] objectForKey:ToBeChangeTask_Save];
            
            for (int i = 0;i < writeArray.count; i ++) {
                NSDictionary *ccc = [writeArray objectAtIndex:i];
                for (int j = 0;j < saveArray.count; j++) {
                    //NSMutableDictionary *ddddd = [[NSMutableDictionary alloc] initWithDictionary:bbbb];
                    NSDictionary *bbbb = [saveArray objectAtIndex:j];
                    if ([[ccc valueForKey:@"InspectTaskID"] intValue] == [[bbbb valueForKey:@"InspectTaskID"] intValue]) {
                        [writeArray replaceObjectAtIndex:i withObject:bbbb];
                    }
                }
                
            }
            
            //writeArray = saveArray;
            
            
//            NSArray *tempArray = [[NSUserDefaults standardUserDefaults] objectForKey:Check_Type_Items];
//            if (tempArray != nil && tempArray.count > 0) {
//                
//            }else{
                [self getCheckData];
//            }
            
            
                    }
    }else if ([_currentStr isEqualToString:@"Check_Type_Items"]){
        if ([[YMNetDataUtil getSuccessState:body] intValue] == 1)
        {
//            NSArray *arrayT = [[NSUserDefaults standardUserDefaults] objectForKey:select_RiskLevel];
//            if (arrayT != nil && arrayT.count > 0) {
//            }else{
                [self getLevelData];
//            }

            
            [[NSUserDefaults standardUserDefaults] setObject:[body valueForKey:@"DicList"] forKey:Check_Type_Items];
            [_myTable reloadData];
        }
        
    }else if ([_currentStr isEqualToString:@"select_RiskLevel"]){
        {
            [[NSUserDefaults standardUserDefaults] setObject:[body valueForKey:@"DicList"] forKey:select_RiskLevel];
            [_myTable reloadData];
        }
        
    }else{
        if ([[YMNetDataUtil getSuccessState:body] intValue] == 1)
        {
            if ([self.delegate respondsToSelector:@selector(reloadData)]) {
                [self.delegate reloadData];
            }
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}

- (void)getLevelData{
    [[YMNetLib getInstance] connectWithAction:Dictionary_Type_API method:@"GET" withContent:@"DicType=RiskLevel" withBody:nil withDelegate:self];
    _currentStr = @"select_RiskLevel";
}

- (void)getCheckData{
    [[YMNetLib getInstance] connectWithAction:Dictionary_Type_API method:@"GET" withContent:@"DicType=InspectType" withBody:nil withDelegate:self];
    _currentStr = @"Check_Type_Items";
}


- (void)viewDidLoad {
    self.navTitle = @"问题整改";
    [super viewDidLoad];
    
    TMP_UPLOAD_IMG_PATH = @"";
    
    _titleArray = @[@"检查内容",@"检查单信息"];
    
    //writeArray = [[NSMutableArray alloc] initWithCapacity:3];
    [self initSelectView];
    [self initSecondTable];
}

- (void)initSelectView{
    _segementView = [[HTHorizontalSelectionList alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kDeviceWidth, 40.0f)];
    _segementView.delegate = self;
    _segementView.dataSource = self;
    _segementView.autoFillWidth = YES;
    _segementView.font = 14;
    _segementView.sideMargin = 0;
    _segementView.isAdjustBottomLine = YES;
    _segementView.bottomLineMargin = 10.f;
    _segementView.selectionIndicatorColor = kBlueColor;
    [_segementView setSelectedButtonIndex:0];
    [_segementView setTitleColor:kGreenColor forState:UIControlStateNormal];
    [_segementView setBottomTrimColor:kGreenColor];
    [self.view addSubview:_segementView];
}

- (void)initTable
{
    _myTable = [[UITableView alloc] init];
    _myTable.frame = CGRectMake(0.0f,_segementView.bottom, kDeviceWidth, kDeviceHeight-NAV_HEIGHT-kTabHeight-_segementView.height);
    _myTable.delegate = self;
    _myTable.dataSource = self;
    _myTable.backgroundColor = kRGB(241, 246, 250);
    _myTable.tag = 116;
    [self.view addSubview:_myTable];
}

- (void)initSecondTable
{
    _secondTable = [[UITableView alloc] init];
    _secondTable.frame = CGRectMake(0.0f,_segementView.bottom, kDeviceWidth, 54.0f*5.0f);
    _secondTable.delegate = self;
    _secondTable.dataSource = self;
    _secondTable.backgroundColor = kRGB(241, 246, 250);
    _secondTable.tag = 118;
    _secondTable.scrollEnabled = NO;
    [self.view addSubview:_secondTable];
}


- (void)initFooter
{
    _footView = [[UIView alloc] init];
    _footView.frame = CGRectMake(0.0f, self.view.height-kTabHeight, kDeviceWidth, kTabHeight);
    _footView.backgroundColor = kWhiteColor;
    [self.view addSubview:_footView];
    
    UIButton *refuseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    refuseBtn.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, kTabHeight);
    [refuseBtn setBackgroundColor:kBlueColor];
    [refuseBtn setTitle:@"上传" forState:UIControlStateNormal];
    //refuseBtn.layer.cornerRadius = 5.0f;
    //refuseBtn.layer.masksToBounds = YES;
    refuseBtn.tag = 119;
    [refuseBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [_footView addSubview:refuseBtn];
}

- (void)btnAction:(UIButton*)sender
{
    switch (sender.tag) {
        case 116:
        {
            //SeePictureViewController *seeVC = [[SeePictureViewController alloc] initWithArray:[_dataDic objectForKey:@"RiskAttshUrlList"]];
            //[self.navigationController pushViewController:seeVC animated:YES];
        }
            break;
        case 118:
        {
            //WriteToBeChangeTaskViewController *writeVC = [[WriteToBeChangeTaskViewController alloc] init];
            //writeVC.navTitle = @"填写整改";
            //writeVC.delegate = self;
            //[self.navigationController pushViewController:writeVC animated:YES];
        }
            break;
        case 119:
        {
            [[YMUIUtil getInstance] hideLoadingView];
            [[YMUIUtil getInstance] showLoadingWithTitle:@"加载中..."];
            
            //
            //            BOOL isSelect = NO;
            //
            //            for (int i = 0; i < dataArray.count; i++)
            //            {
            //                NSDictionary *tempD = [dataArray objectAtIndex:i];
            //                if ([[tempD valueForKey:@"isSelect"] boolValue]) {
            //                    isSelect = YES;
            //                }
            //            }
            //            if (!isSelect) {
            //                [[YMUIUtil getInstance] hideLoadingView];
            //
            //            }
            
            BOOL isAttack = NO;
            for (NSDictionary *aaa in writeArray) {
                NSArray *tempAAA = [aaa objectForKey:@"AttachList"];
                if (tempAAA == nil || tempAAA.count <= 0) {
                    isAttack = YES;
                }
            }
            if (isAttack) {
                [[YMUIUtil getInstance] hideLoadingView];
                [[YMUIUtil getInstance] showTipViewAutoDis:@"请先完善整改信息"];
                return;
            }
            [self performSelector:@selector(uploadTestAction) withObject:nil afterDelay:1.0f];
        }
            break;
            
        default:
            break;
    }
}

- (void)uploadTestAction{
    NSMutableArray *RepairRecordList = [[NSMutableArray alloc] initWithCapacity:3];
    [RepairRecordList removeAllObjects];
    for (NSDictionary *yyyy in writeArray) {
        
        NSArray *imageList = [yyyy objectForKey:@"AttachList"];
        
        NSMutableArray *idList = [[NSMutableArray alloc] initWithCapacity:3];
        [idList removeAllObjects];
        
        for (int j = 0; j < imageList.count; j ++) {
            
            //[hImageView setImage:tempImage];
            NSLog(@"===TMP_UPLOAD_IMG_PATH===%@",TMP_UPLOAD_IMG_PATH);
            NSData* imageData = [imageList objectAtIndex:j];//UIImagePNGRepresentation(tempImage);
            
            NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
            
            NSString* documentsDirectory = [paths objectAtIndex:0];
            
            // Now we get the full path to the file
            
            NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%@",[self generateUuidString],@".jpg"]];
            
            // and then we write it out
            TMP_UPLOAD_IMG_PATH=fullPathToFile;
            NSArray *nameAry=[TMP_UPLOAD_IMG_PATH componentsSeparatedByString:@"/"];
            NSLog(@"===new fullPathToFile===%@",fullPathToFile);
            NSLog(@"===new FileName===%@",[nameAry objectAtIndex:[nameAry count]-1]);
            
            [imageData writeToFile:fullPathToFile atomically:NO];
            
            //[self onPostData];
            
            NSMutableDictionary * dir=[NSMutableDictionary dictionaryWithCapacity:7];
            //[dir setValue:@"save" forKey:@"m"];
            [dir setValue:[[UserInfo getInstance] getUserID] forKey:@"UserID"];
            [dir setValue:[[UserInfo getInstance] getUseToken] forKey:@"UserToken"];
            NSString *url= kAppApi(Upload_File);
            NSLog(@"=======上传%@", url);
            if([TMP_UPLOAD_IMG_PATH isEqualToString:@""]){
                [RequestPostUploadHelper postRequestWithURL:url postParems:dir picFilePath:nil picFileName:nil];
            }else{
                NSLog(@"有图标上传");
                NSArray *nameAry=[TMP_UPLOAD_IMG_PATH componentsSeparatedByString:@"/"];
                NSString *result =  [RequestPostUploadHelper postRequestWithURL:url postParems:dir picFilePath:TMP_UPLOAD_IMG_PATH picFileName:[nameAry objectAtIndex:[nameAry count]-1]];
                NSDictionary *resultDic = [self dictionaryWithJsonString:result];
                
                
                NSArray *imageID = [resultDic objectForKey:@"ResourcesList"];
                for (NSDictionary *ggg in imageID) {
                    [idList addObject:[NSNumber numberWithInt:[[ggg valueForKey:@"ResourceId"] intValue]]];
                    //[idList addObject:[NSString stringWithFormat:@"%d",[[ggg valueForKey:@"ResourceId"] intValue]]];
                    //[idList addObject:@"209"];
                }
            }
        }
        
        NSMutableDictionary *bbb = [[NSMutableDictionary alloc] initWithCapacity:3];
        [bbb setValue:[NSNumber numberWithInt:[[yyyy valueForKey:@"InspectTaskID"] intValue]] forKey:@"InspectTaskID"];
        //[bbb setObject:[yyyy objectForKey:@"AttachList"] forKey:@"AttachList"];
        [bbb setObject:idList forKey:@"AttachList"];
        [bbb setValue:[yyyy valueForKey:@"RepairDesc"] forKey:@"RepairDesc"];
        [RepairRecordList addObject:bbb];
    }
    
    NSDictionary *bodyD = [NSDictionary dictionaryWithObjectsAndKeys:
                           [[UserInfo getInstance] getUserID],@"UserID",
                           [NSNumber numberWithInt:[[_dataDic valueForKey:@"InspectionID"] intValue]],@"InspectionID",
                           [NSNumber numberWithInt:[[_dataDic valueForKey:@"InspectItemID"] intValue]],@"InspectionItemID",
                           [NSNumber numberWithInt:0],@"RiskID",
                           RepairRecordList,@"RepairRecordList",
                           nil];
    
    [[YMNetLib getInstance] connectWithAction:Upload_DaiZhengGai method:@"POST" withContent:nil withBody:bodyD withDelegate:self];
    _currentStr = Upload_DaiZhengGai;
}

- (void)passValue:(NSDictionary *)data{
    //NSMutableArray *aaaa = writeArray;
    for (int i = 0;i < writeArray.count; i ++) {
        //for (NSDictionary *ccc in writeArray) {
        NSDictionary *ccc = [writeArray objectAtIndex:i];
        NSMutableDictionary *ddddd = [[NSMutableDictionary alloc] initWithDictionary:ccc];
        if ([[ccc valueForKey:@"InspectTaskID"] intValue] == [[data valueForKey:@"InspectTaskID"] intValue]) {
            [ddddd setValue:[data valueForKey:@"Write_WenTi"] forKey:@"RepairDesc"];
            [ddddd setObject:[data objectForKey:@"Image_List"] forKey:@"AttachList"];
            [writeArray replaceObjectAtIndex:i withObject:ddddd];
        }
    }
    /*
     {
     AttachList =     (
     
     );
     InspectContentAuditStatus = "";
     InspectContentDesc = "\U4e34\U8fb9\U4f5c\U4e1a\U65e0\U9632\U62a4\U63aa\U65bd";
     InspectContentStatus = 0;
     InspectRiskDesc = "\U54c8\U54c8\U54c8\U54c8";
     InspectTaskID = 115;
     Points = 5;
     RepairDesc = "\U6478\U6478\U54e6\U54e6\U5f04";
     RiskAttshUrlList =     (
     "http://qsms.ccshj.net:8081/api/sqcp/resource/GetResourceContent?id=73"
     );
     RiskType = 0;
     RiskTypeName = "\U5b89\U5168\U7ba1\U7406";
     TaskDeadLine = "2016-07-31T11:44:46";
     }
     */
    NSMutableArray *uuu = [[NSMutableArray alloc] initWithCapacity:3];
    [uuu removeAllObjects];
    for (NSDictionary *aaa in writeArray) {
        NSArray *tempAAA = [aaa objectForKey:@"AttachList"];
        if (tempAAA != nil && tempAAA.count >= 0) {
            NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:aaa];
            [dic setValue:[_dataDic valueForKey:@"InspectItemID"] forKey:@"InspectItemID"];
            [dic setValue:[_dataDic valueForKey:@"InspectionID"] forKey:@"InspectionID"];
            [uuu addObject:dic];
        }else{
            NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithCapacity:3];
            [dic setValue:[_dataDic valueForKey:@"InspectItemID"] forKey:@"InspectItemID"];
            [dic setValue:[_dataDic valueForKey:@"InspectionID"] forKey:@"InspectionID"];
            [uuu addObject:dic];
        }
    }
    [[NSUserDefaults standardUserDefaults] setObject:uuu forKey:ToBeChangeTask_Save];
}


#pragma mark  ************************* UITableViewDataSource **************************************
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView.tag == 116) {
        return 2;
    }else{
        return 1;
    }
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView.tag == 116) {
        if (section == 0) {
            return 2;
        }else{
            NSArray *sss = [_dataDic objectForKey:@"InspectTaskList"];
            return sss.count;
        }
    }else{
        return 5;
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView.tag == 116) {
        if (indexPath.section == 0) {
            
            static NSString *identifier = @"cell_house_History";
            UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
            if (cell == nil)
            {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            }
            cell.textLabel.textColor = kRGB(205, 206, 207);
            cell.textLabel.font = kAppFont(Home_Small_Size+2);
            cell.detailTextLabel.font = kAppFont(Home_Small_Size);
            cell.detailTextLabel.textColor = kRGB(100, 99, 104);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            switch (indexPath.row) {
                case 0:
                {
                    cell.accessoryType = UITableViewCellAccessoryNone;
                    cell.textLabel.text = @"任务名称";
                    cell.detailTextLabel.text = [_dataDic valueForKey:@"InspectTaskName"];
                }
                    break;
                    
                case 1:
                {
                    cell.accessoryType = UITableViewCellAccessoryNone;
                    cell.textLabel.text = @"截止日期";
                    NSString *dateStr = [_dataDic valueForKey:@"DeadLine"];
                    //dateStr = [dateStr stringByReplacingOccurrencesOfString:@"T" withString:@" "];
                    NSArray *ddd = [dateStr componentsSeparatedByString:@"T"];
                    if (ddd != nil && ddd.count >= 2) {
                        cell.detailTextLabel.text = [ddd objectAtIndex:0];//@"2016-06-06";
                    }
                    
                    
                    UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
                    arrowImageView.frame = CGRectMake(kDeviceWidth-16.0f-10.0f/2.0f, (54.0f-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
                    cell.accessoryView = arrowImageView;
                    
                    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 53.5f, kDeviceWidth, 0.5f)];
                    lineView.backgroundColor = kGreenColor;
                    [cell addSubview:lineView];
                    
                }
                    break;
                default:
                    break;
            }
            
            return cell;
        }else{
            NSArray *sss = [_dataDic objectForKey:@"InspectTaskList"];
            
            static NSString *identifier = @"ToBeChangeTaskDetailCell";
            ToBeChangeTaskDetailCell *cell2 = (ToBeChangeTaskDetailCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
            if (cell2 == nil)
            {
                cell2 = [[ToBeChangeTaskDetailCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            }
            cell2.textLabel.textColor = kRGB(205, 206, 207);
            cell2.textLabel.font = kAppFont(Home_Small_Size+2);
            cell2.detailTextLabel.font = kAppFont(Home_Small_Size);
            cell2.detailTextLabel.textColor = kRGB(100, 99, 104);
            cell2.selectionStyle = UITableViewCellSelectionStyleNone;
            
            [cell2.seeBtn addTarget:self action:@selector(seeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
            cell2.seeBtn.tag = indexPath.row;
            
            [cell2.passBtn addTarget:self action:@selector(passBtnAction:) forControlEvents:UIControlEventTouchUpInside];
            cell2.passBtn.tag = indexPath.row;
            
            [cell2.fullControl addTarget:self action:@selector(checkFullControlAction:) forControlEvents:UIControlEventTouchUpInside];
            cell2.fullControl.tag = indexPath.row;
            
            
            
            NSDictionary *nnn = [sss objectAtIndex:indexPath.row];
            [cell2 showWithData:nnn];
            
            return cell2;
        }
    }else{
        static NSString *identifier = @"cell_house_History";
        UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        }
        cell.textLabel.textColor = kRGB(205, 206, 207);
        cell.textLabel.font = kAppFont(Home_Small_Size+2);
        cell.detailTextLabel.font = kAppFont(Home_Small_Size);
        cell.detailTextLabel.textColor = kRGB(100, 99, 104);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        switch (indexPath.row) {
            case 0:
            {
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.textLabel.text = @"检查专业";
                cell.detailTextLabel.text = [_dataDic valueForKey:@"InspectProfessionName"];
                
                //UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
                //arrowImageView.frame = CGRectMake(kDeviceWidth-16.0f-10.0f/2.0f, (54.0f-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
                
                //cell.accessoryView = arrowImageView;
                
                //UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(16.0f, 53.5f, kDeviceWidth-16.0f, 0.5f)];
                //lineView.backgroundColor = kGreenColor;
                //[cell addSubview:lineView];
            }
                break;
            case 1:
            {
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.textLabel.text = @"检查项";
                cell.detailTextLabel.text = [_dataDic valueForKey:@"InspectItemName"];
            }
                break;
            case 2:
            {
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.textLabel.text = @"所属公司";
                cell.detailTextLabel.text = [_dataDic valueForKey:@"InspectOrgName"];//InspectOrgName
            }
                break;
            case 3:
            {
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.textLabel.text = @"所属项目部";
                cell.detailTextLabel.text = [_dataDic valueForKey:@"InspectProjectDPTName"];
            }
                break;
            case 4:
            {
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.textLabel.text = @"检查类型";
                NSArray *tempArray = [[NSUserDefaults standardUserDefaults] objectForKey:Check_Type_Items];
                for (NSDictionary *hhh in tempArray) {
                    if ([[hhh valueForKey:@"Value"] intValue] == [[_dataDic valueForKey:@"InspectType"] intValue]) {
                        cell.detailTextLabel.text = [hhh valueForKey:@"Name"];
                    }
                }
                //cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", [[_dataDic valueForKey:@"InspectType"] intValue]];
            }
                break;
                //            case 5:
                //            {
                //                cell.accessoryType = UITableViewCellAccessoryNone;
                //                cell.textLabel.text = @"隐患类别";
                //                NSArray *arrayT = [[NSUserDefaults standardUserDefaults] objectForKey:select_RiskLevel];
                //                for (NSDictionary *yyy in arrayT) {
                //                    if ([[yyy valueForKey:@"Value"] intValue] == [[_dataDic valueForKey:@"RiskLevel"] intValue]) {
                //                        cell.detailTextLabel.text = [yyy valueForKey:@"Name"];
                //                    }
                //                }
                //
                //            }
                //                break;
            default:
                break;
        }
        
        return cell;
    }
    
    
    return nil;
}

- (void)seeBtnAction:(UIButton*)sender{
    NSArray *sss = [_dataDic objectForKey:@"InspectTaskList"];
    NSDictionary *nnn = [sss objectAtIndex:sender.tag];
    /*
    SeePictureViewController *seeVC = [[SeePictureViewController alloc] initWithArray:[nnn objectForKey:@"RiskAttshUrlList"]];
    [self.navigationController pushViewController:seeVC animated:YES];
    */
    
    JZAlbumViewController *jzAlbumVC = [[JZAlbumViewController alloc] init];
    
    jzAlbumVC.currentIndex =0;//这个参数表示当前图片的index，默认是0
    
    jzAlbumVC.imgArr = [nnn objectForKey:@"RiskAttshUrlList"];//图片数组，可以是url，也可以是UIImage
    [self.navigationController pushViewController:jzAlbumVC animated:YES];
    //[self presentModalViewController:jzAlbumVC animated:YES];
}

- (void)passBtnAction:(UIButton*)sender{
    NSArray *sss = [_dataDic objectForKey:@"InspectTaskList"];
    NSDictionary *nnn = [sss objectAtIndex:sender.tag];
    WriteToBeChangeTaskViewController *writeVC = [[WriteToBeChangeTaskViewController alloc] initWithData:nnn superDic:_dataDic];
    writeVC.navTitle = @"填写整改";
    writeVC.delegate = self;
    [self.navigationController pushViewController:writeVC animated:YES];
}

- (void)checkFullControlAction:(UIControl*)sender{
    NSArray *sss = [_dataDic objectForKey:@"InspectTaskList"];
    NSDictionary *nnn = [sss objectAtIndex:sender.tag];
    WriteToBeChangeTaskViewController *writeVC = [[WriteToBeChangeTaskViewController alloc] initWithData:nnn superDic:_dataDic];
    writeVC.navTitle = @"填写整改";
    writeVC.delegate = self;
    [self.navigationController pushViewController:writeVC animated:YES];
}

//- (void)checkItemControlAction:(UIControl*)sender{
//    NSArray *sss = [_dataDic objectForKey:@"InspectTaskList"];
//    NSDictionary *nnn = [sss objectAtIndex:sender.tag];
//}




-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 116) {
        if (indexPath.section == 0) {
            return 54.0f;
        }else{
            return 54.0f*4.0f+10.0f;
        }
    }else{
        return 54.0f;
    }
    
    return 0.0f;
}


#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /*
     switch (indexPath.row) {
     case 7:
     {
     
     [_datePicker removeFromSuperview];
     _datePicker = nil;
     _datePicker = [[UIDatePicker alloc] init];
     _datePicker.datePickerMode = UIDatePickerModeDateAndTime;
     _datePicker.minimumDate = [NSDate date];
     _datePicker.frame = CGRectMake(0.0f, self.view.height-200.0f, kDeviceWidth, 200.0f);
     _datePicker.backgroundColor = kDefaultBackgroundColor;
     [self.view addSubview:_datePicker];
     
     [_dateTopView removeFromSuperview];
     _dateTopView = nil;
     _dateTopView = [[UIView alloc] init];
     _dateTopView.backgroundColor = kWhiteColor;
     _dateTopView.frame = CGRectMake(-0.5f, self.view.height-_datePicker.height-40.0f, kDeviceWidth+1.0f, 40.0f);
     _dateTopView.layer.borderColor = kGreenColor.CGColor;
     _dateTopView.layer.borderWidth = 0.5f;
     [self.view addSubview:_dateTopView];
     
     UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
     [sureBtn setTitle:@"确认" forState:UIControlStateNormal];
     [sureBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
     sureBtn.titleLabel.font = kAppFont(Home_Big_Size);
     sureBtn.frame = CGRectMake(kDeviceWidth-40.0f-16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
     [sureBtn addTarget:self action:@selector(sureBtnAcion) forControlEvents:UIControlEventTouchUpInside];
     [_dateTopView addSubview:sureBtn];
     
     UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
     [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
     [cancleBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
     cancleBtn.titleLabel.font = kAppFont(Home_Big_Size);
     cancleBtn.frame = CGRectMake(16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
     [cancleBtn addTarget:self action:@selector(cancleBtnAcion) forControlEvents:UIControlEventTouchUpInside];
     [_dateTopView addSubview:cancleBtn];
     
     }
     break;
     
     default:
     break;
     
     }
     */
}

/*
 - (void)sureBtnAcion
 {
 NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
 // 格式化日期格式
 formatter. dateFormat = @"yyyy:MM:dd HH:mm:ss" ;
 _dateStr = [formatter stringFromDate:_datePicker.date];
 NSLog(@"=====%@", _dateStr);
 
 
 [_datePicker removeFromSuperview];
 _datePicker = nil;
 [_dateTopView removeFromSuperview];
 _dateTopView = nil;
 
 [_myTable reloadData];
 }
 
 - (void)cancleBtnAcion
 {
 [_datePicker removeFromSuperview];
 _datePicker = nil;
 [_dateTopView removeFromSuperview];
 _dateTopView = nil;
 }
 */


#pragma mark - HTHorizontalSelectionList delegate
- (NSInteger)numberOfItemsInSelectionList:(HTHorizontalSelectionList *)selectionList
{
    return _titleArray.count;
}

- (NSString *)selectionList:(HTHorizontalSelectionList *)selectionList titleForItemWithIndex:(NSInteger)index
{
    return _titleArray[index];
}

- (void)selectionList:(HTHorizontalSelectionList *)selectionList didSelectButtonWithIndex:(NSInteger)index
{
    switch (index) {
        case 0:
        {
            [_secondTable removeFromSuperview];
            
            [self.view addSubview:_myTable];
            [self.view addSubview:_footView];
            
            [_myTable reloadData];
        }
            break;
        case 1:
        {
            [_myTable removeFromSuperview];
            [_footView removeFromSuperview];
            
            [self.view addSubview:_secondTable];
            [_secondTable reloadData];
        }
            break;
            
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (NSString *)generateUuidString
{
    // create a new UUID which you own
    CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
    
    // create a new CFStringRef (toll-free bridged to NSString)
    // that you own
    NSString *uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, uuid));
    
    // transfer ownership of the string
    // to the autorelease pool
    //[uuidString autorelease];
    
    // release the UUID
    CFRelease(uuid);
    
    return uuidString;
}

- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}


@end
